package net.apps.std;

import net.apps.core.meta.AField;
import net.apps.core.meta.AMessage;
import net.apps.core.meta.AProtocol;
import net.apps.core.meta.Meta;

@AProtocol(name="net.apps.std.Text", description="Text input and editors")
public class TextMessageProtocol extends AbsProtocol {
	
	static final int ID_MSG_TEXT = 1;
	
	public TextMessageProtocol(Meta meta) {
		super(meta);
	}
	
	@AMessage(id=ID_MSG_TEXT, name="Text", description="Text input message")
	final class TextMessage extends AbsMessage {
		@AField(id=0, description="Input text")
		final String text;
		
		TextMessage(String text) {
			this.text = text;
		}
	}

//	@Override
//	public Message encode(Message data)  throws Exception {
//		if (data instanceof TextMessageFactory.TextMessage) {
//			TextMessageFactory.TextMessage text_msg = (TextMessageFactory.TextMessage)data;
//			EditTextProtos.Generic proto_msg = EditTextProtos.Generic.newBuilder()
//					.setText(text_msg.text)
//					.build();
//			return proto_msg.toByteArray();
//		}
//		return null;
//	}
//
//	@Override
//	public Message decode(Message data) throws Exception {
//		if (data instanceof byte[]) {
//			final EditTextProtos.Generic gen = EditTextProtos.Generic.parseFrom((byte[])data);
//			String text = "";
//			if (gen.hasText())
//				text = gen.getText();
//			TextMessageFactory.TextMessage text_msg = TextMessageFactory.instance.makeTextMessage(text);
//			return text_msg;
//		}
//		return null;
//	}

}
